import { remoteList } from "@/api/system/dict";
import { message } from "ant-design-vue";

export const useDicts = (types: string[]) => {
    let state = reactive<any>({
        dicts: {}
    });

    onMounted(() => {
        dealDicts();
    });

    const dealDicts = () => {
        if (!Array.isArray(types)) {
            state.dicts = {}
            return false;
        }
        types.map(async (dict_code) => {
            try {
                let result = await remoteList({ page: 1, size: 100, dict_code });
                state.dicts[dict_code] = result.data.list;
            } catch (err: any) {
                message.error(err.msg)
            }
        })
    }
    return {
        ...toRefs(state)
    }
}